package api

import (
	"api-getaway/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Upload(r *gin.Context) {
	file, err := r.FormFile("image")
	if err != nil {
		return
	}

	upload, err := pkg.Upload(file)
	if err != nil {
		r.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "图片上传失败",
			"data":    err.Error(),
		})
		return
	}
	r.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "图片上传成功",
		"data":    upload,
	})
}
